package com.dawn.cloud.pos.drive.sdk;


import com.cdbkj.cloud.pos.bean.Filed;
import com.cdbkj.cloud.pos.bean.PrintModel;
import com.dawn.cloud.pos.drive.hardware.printer.PosPrinter;

import java.util.List;

/**
 * @author yyh
 *
 * @date 2018/07/05
 *
 * @description 打印SDK
 */
public class PrintSdk {

	public static void print(List<PrintModel> listModel, String receiptType, String title, String regDate, String patientId,String msg) {
		boolean isOpenSuccess = PosPrinter.getPrinter().openPrinter();
		if (isOpenSuccess) {
			PosPrinter.getPrinter().printText(title,
					PosPrinter.FONT_TYPE_STANDARD_ASCII, PosPrinter.FONT_STYLE_BOLD,
					PosPrinter.TEXT_ALIGNMENT_CENTER, 0, 0, 30, 2, 2);

			PosPrinter.getPrinter().printText("   ",
					PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
					PosPrinter.TEXT_ALIGNMENT_CENTER, 0, 0, 10, 1, 1);

			PosPrinter.getPrinter().printText("------"+regDate+"------",
					PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
					PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 40, 1, 1);
			for (PrintModel printModel : listModel) {
				PosPrinter.getPrinter().printText(printModel.getName()+": "+printModel.getVal(),
						PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
						PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 30, 1, 1);
			}
			PosPrinter.getPrinter().printText("--------------------------------",
					PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
					PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 30, 1, 1);

			if(receiptType.equals(Filed.RECEIPT_TYPE_PAY_REGISTER)){
				PosPrinter.getPrinter().printText("温馨提示：",
						PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
						PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 40, 1, 1);
				PosPrinter.getPrinter().printText(msg,
						PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
						PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 40, 1, 1);

			}

			PosPrinter.getPrinter().printText("   ",
					PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
					PosPrinter.TEXT_ALIGNMENT_CENTER, 0, 0, 30, 1, 1);
			PosPrinter.getPrinter().cutPaper();


			//打印两张小票，留作凭条

			PosPrinter.getPrinter().printText(title,
					PosPrinter.FONT_TYPE_STANDARD_ASCII, PosPrinter.FONT_STYLE_BOLD,
					PosPrinter.TEXT_ALIGNMENT_CENTER, 0, 0, 30, 2, 2);

			PosPrinter.getPrinter().printText("   ",
					PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
					PosPrinter.TEXT_ALIGNMENT_CENTER, 0, 0, 10, 1, 1);

			PosPrinter.getPrinter().printText("------"+regDate+"------",
					PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
					PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 40, 1, 1);
			for (PrintModel printModel : listModel) {
				PosPrinter.getPrinter().printText(printModel.getName()+": "+printModel.getVal(),
						PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
						PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 30, 1, 1);
			}
			PosPrinter.getPrinter().printText("--------------------------------",
					PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
					PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 30, 1, 1);

			if(receiptType.equals(Filed.RECEIPT_TYPE_PAY_REGISTER)){
				PosPrinter.getPrinter().printText("温馨提示：",
						PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
						PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 40, 1, 1);
				PosPrinter.getPrinter().printText(msg,
						PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
						PosPrinter.TEXT_ALIGNMENT_LEFT, 0, 0, 40, 1, 1);

			}

			PosPrinter.getPrinter().printText("   ",
					PosPrinter.FONT_TYPE_STANDARD_ASCII, 0,
					PosPrinter.TEXT_ALIGNMENT_CENTER, 0, 0, 30, 1, 1);
			PosPrinter.getPrinter().cutPaper();

			PosPrinter.getPrinter().closePrinter();
		}
	}
}
